import request from "@/utils/request";

// 用户分页查询
export const queryUserPageApi = (params) =>
  request.get("/users", { params: params });

// 查询所有部门
export const queryDeptListApi = () => request.get("/depts/list");

// 查询所有角色
export const queryRoleListApi = () => request.get("/roles/list");

// 添加用户
export const addUserApi = (data) => request.post("/users", data);

// 根据ID查询用户
export const getUserByIdApi = (id) => request.get(`/users/${id}`);

// 修改用户
export const updateUserApi = (data) => request.put("/users", data);

// 删除用户
export const deleteUserApi = (id) => request.delete(`/users/${id}`);

// 批量删除用户
export const batchDeleteUserApi = (ids) =>
  request.delete(`/users/batch`, { data: ids });

// 文件上传
export const uploadImageApi = (file) => {
  const formData = new FormData();
  formData.append("image", file);

  console.log("准备上传文件:", {
    fileName: file.name,
    fileSize: file.size,
    fileType: file.type,
    formData: formData,
  });

  // 移除手动设置的Content-Type，让浏览器自动设置
  return request.post("/upload", formData);
};
